package com.ucar.modules.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ucar.modules.demo.dao.DemoDao;
import com.ucar.modules.demo.entity.Demo;
import com.ucar.modules.demo.service.DemoService;

@Service("demoService")
public class DemoServiceImpl implements DemoService {
	@Autowired
	private DemoDao demoDao;

	@Override
	public String test() {
		return "hello world";
	}

	@Override
	public Demo getById(Integer id) {
		return demoDao.getById(id);
	}

	@Override
	public List<Demo> getList(String name) {
		return demoDao.getList(name);
	}

	@Override
	public int add(Demo demo) {
		return demoDao.add(demo);
	}

	@Override
	public int edit(Demo demo) {
		return demoDao.edit(demo);
	}

	@Override
	public int deleteById(Integer id) {
		return demoDao.deleteById(id);
	}

	@Override
	public List<Demo> getPage(Integer pageNum, Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Demo> list = demoDao.getList("");
		PageInfo<Demo> pageInfo = new PageInfo<Demo>(list);
		return pageInfo.getList();
	}

	@Override
	public PageInfo<Demo> getPageInfo(Integer pageNum, Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Demo> list = demoDao.getList("");
		return new PageInfo<Demo>(list);
	}

	@Override
	public List<Demo> getNativityPage(Integer pageNum, Integer pageSize) {
		return demoDao.getNativityList((pageNum - 1) * pageSize, pageSize);
	}
}
